package top.roadvast.pdshopping.service.impl;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Service;
import top.roadvast.pdshopping.bean.PdLog;
import top.roadvast.pdshopping.bean.PdOrder;
import top.roadvast.pdshopping.service.OrderService;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @Author 郭泽鹏
 * @Date 2021/12/27 19:53
 * @Version 1.0
 * @Description 订单业务层
 */
@Service
public class OrderServiceImpl implements OrderService {
    @Resource
    AmqpTemplate amqpTemplate;

    @Override
    public String saveOrder(PdOrder order) {
        final String orderCode = UUID.randomUUID().toString();
        order.setOrderCode(orderCode.replaceAll("-", ""));
        //参数一：队列，参数二：消息
        // 将订单信息放到rabbitmq，然后返回订单编号
        //默认是已经将消息持久化了。
        amqpTemplate.convertAndSend("order_queue", order);
        return orderCode;
    }
}
